<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li{
            list-style: none;
            width: 100px;
            border: 1px solid;
        }
        .nav ul{
            display: flex;
            /* justify-content: center; */
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="nav">
            <ul>
                <li>
                    <router-link to="/my?id=1">我的</router-link>
                </li>
                <li>
                    <router-link to="/find/12/张三">发现</router-link>
                </li>
            </ul>
        </div>
        <!--  -->
        <div class="viewList">
            <router-view></router-view>
        </div>
    </div>
    <!-- 我的组件模板 -->
    <template id="my">
        <div>
            <!-- 接收参数 -->
            {{this.$route.query.id}}
            <h1>{{user.name}}</h1>
            <h1>{{user.sex}}</h1>
            <h1>{{user.age}}</h1>
        </div>
    </template>
        <!-- 发现组件模板 -->
    <template id="find">
        <div>
            {{this.$route.params.id}}
            <h1>发现组件</h1>
            <h1>发现组件</h1>
            <h1>发现组件</h1>
        </div>
    </template>
</body>
</html>
<script type="module">
    import {} from './js/vue.js';
    import {} from './js/vue-router.js';
    
    var my = {
        template:'#my',
        props:[],
        data() {
            return {
                user:{}
            }
        },
        methods:{
            getUserInfo(id){
                if(id==1){
                    this.user = {id:'1',name:'admin',sex:'男',age:18}
                }else if(id==2){
                    this.user = {id:'2',name:'李四',sex:'男',age:29}
                }else if(id==3){
                    this.user = {id:'3',name:'张三',sex:'男',age:100}
                }
            }
        },
        created() {
            //获取路由参数
            var id = this.$route.query.id;
            this.getUserInfo(id);
        },
        
    }
    var find = {
        template:'#find',
        props:[]
    }
    
    var routes = [
        {path:'/my',component:my},
        // 动态参数
        {path:'/find/:id/:name',component:find}
    ]
    var router = new VueRouter({
        routes,
    })
    new Vue({
        el:'#app',
        data:{
            
        },
        methods: {
            
        },
        router
    })
</script>